#include "HostStatusWnd.h"

BOOL HostStatusWnd::OnInitDialog(){
    if (!CMzWndEx::OnInitDialog()){
        return FALSE;
    }

    m_List.SetPos(0, 0, GetWidth(), GetHeight()-MZM_HEIGHT_TEXT_TOOLBAR);
    m_List.SetID(SM_IDC_LIST);
    m_List.EnableScrollBarV(true);
    m_List.EnableNotifyMessage(true);
    AddUiWin(&m_List);

    ListItem li;
    li.Text = SM_TEXT_LI_LOCAL;
    m_List.AddItem(li);
    li.Text = SM_TEXT_LI_COUNTRY;
    m_List.AddItem(li);
    li.Text = SM_TEXT_LI_WORLD;
    m_List.AddItem(li);

    m_Toolbar.SetPos(0, GetHeight()-MZM_HEIGHT_TEXT_TOOLBAR,GetWidth(), MZM_HEIGHT_TEXT_TOOLBAR);
    m_Toolbar.SetID(SM_IDC_TOOLBAR);
    m_Toolbar.SetButton(0, true, true, SM_TEXT_TOOLBAR_CANCEL);
    m_Toolbar.SetButton(2, true, true, SM_TEXT_TOOLBAR_OK);
    AddUiWin(&m_Toolbar);

    return TRUE;

};

void HostStatusWnd::OnMzCommand(WPARAM wParam, LPARAM lParam){
    return EndModal(ID_CANCEL);
};

LRESULT HostStatusWnd::MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam){
    switch(message){
        case MZ_WM_MOUSE_NOTIFY:{
            int nID = LOWORD(wParam);
            int nNotify = HIWORD(wParam);
            int x = LOWORD(lParam);
            int y = HIWORD(lParam);
            if (nID==SM_IDC_LIST && nNotify==MZ_MN_LBUTTONDOWN){
                if (!m_List.IsMouseDownAtScrolling() && !m_List.IsMouseMoved()){
                    int nIndex = m_List.CalcIndexOfPos(x, y);
                    m_List.SetSelectedIndex(nIndex);
                    m_List.Invalidate();
                    m_List.Update();
                }
                return 0;
            }

        };
        return 0;
    };

    return CMzWndEx::MzDefWndProc(message, wParam, lParam);
};

MZ_IMPLEMENT_DYNAMIC(HostStatusWnd);